<template>
    <div style="padding-left:5px;">
<!--        <pre>{{formData}}</pre>-->
        <el-row>
            <el-col align="left">
                <el-form>
                    <el-form-item label="开始数字：">
                        <el-input-number v-model="formData.num1" :min="1"  :step="1"
                        ></el-input-number>
                    </el-form-item>
                    <el-form-item label="结束数字：">
                        <el-input-number v-model="formData.num2" :min="1"  :step="1"
                        ></el-input-number>
                    </el-form-item>
                    <el-form-item label="组：">
                        <el-input v-model="formData.group"
                        ></el-input>
                    </el-form-item>
                    <el-row>
                        <el-col align="center">
                            <el-button type="primary" @click="calc">计算因数</el-button>
                        </el-col>
                    </el-row>

                    <el-form-item label="结果：">
                        <p>如下所示：</p>
                        <div v-for="(resultArr, num) in formData.resultMap" :key="'result_' + num" style="font-size: 30px;">
                            <div >{{num}}的因数（{{resultArr.length}}组）:</div>
                            <div v-for="(result, index) in resultArr" :key="'result_' + index" style="margin-bottom: 10px;">
                                {{result.num1}} × {{result.num2}}
                            </div>
                            <hr/>
                        </div>
                    </el-form-item>
                </el-form>
            </el-col>
        </el-row>
    </div>

</template>

<script>
    /* eslint-disable */

    export default {
        name: 'divide1',
        data() {
            return {
                error: true,
                formData: {
                    num1: 1,
                    num2: 24,
                    group: null,
                    resultMap: {},
                },
            }
        },
        methods: {
            async calc() {
                let resultMap = {}
                for (let i = this.formData.num1; i <= this.formData.num2; i++) {
                    let resultArr = []
                    for (let j = 1; j <= parseInt(Math.sqrt(i)); j++) {
                        if (i % j == 0) {
                            resultArr.push({
                                num1: j,
                                num2: i / j,
                            })
                        }
                    }
                    if (!this.formData.group || this.formData.group == resultArr.length) {
                        resultMap[i] = resultArr
                    }
                }
                this.formData.resultMap = resultMap
                this.$localStorage.set('factor2.formData', this.formData, 4 * 60 * 60 * 1000) // keep 1 day
            },
        },
        computed: {},
        mounted() {
            let formData = this.$localStorage.get('factor2.formData')
            if (formData) {
                this.formData = formData
            }
            this.calc()
        }
    };
</script>
<style>
</style>
